"""
!/usr/bin/env python
-*- coding: utf-8 -*-
@Author  : MarkJia
@Site    : 
@File    : 18、Debig调试错误.py
"""


"""程序调式是将编制的程序投入实际运行前，用手工或编译程序等方法进行测试，修正【语法错误和逻辑错误】的过程"""

# 语法错误
name = 'MackJia'
age = 20
# 不加str转字符串  TypeError: must be str, not int
print('name is ' + name,',age is ' + age )

# 结果为：name is MackJia ,age is 20
print('name is ' + name,',age is ' + str(age))


# 语法错误 下标越界
a = [1, 4, 6]
try:
   a[3]
# IndexError: list index out of range
except Exception as e:
    print(f'异常错误为：{e}')


# 调式  1、print   2、logging

# 逻辑错误  需求：a=1时，返回True   不符合需求

import logging
logging.basicConfig(level=logging.INFO)
a = 1
b = 2
if a == 1:
    flag = True
    # 调式   断点Debug，print 和 logging
    print(f'a == 1时,flag的值是{flag}')
    # logger
    logging.info(f'a == 1时,flag的值是{flag}')
else:
    flag = False
    # 调式   断点Debug，print 和 logging
    print(f'a != 1时,flag的值是{flag}')
    
print(flag)




# 堆栈分析
# 栈：类似木桶放东西 。先入后出

def fun(n):
    print('fun start')
    return n

def add(a,b):
    print('add start')
    result = a + b + fun(10)
    return result

num1 = 1
num2 = 3
x = add(num1,num2)
print(f'调用add方法的结果是：{x}')